﻿using CTM.Web.Data;
using CTM.Web.Models;
using CTM.Web.Repositories;
using System.Linq;

namespace CTM.Web.Services
{
    public interface IAccountService : IApplicationService<ApplicationUser>
    {
        ApplicationUser GetByEmail(string email);
    }

    public class AccountService : ApplicationService<ApplicationUser>, IAccountService
    {
        IUnitOfWork unitOfWork;
        IAccountRepository accountRepository;

        public AccountService(IUnitOfWork unitOfWork, IAccountRepository accountRepository)
            : base(unitOfWork, accountRepository)
        {
            this.unitOfWork = unitOfWork;
            this.accountRepository = accountRepository;
        }

        public ApplicationUser GetByEmail(string email)
        {
            return accountRepository.Get(u => u.Email.ToUpper() == email.ToUpper()).FirstOrDefault();
        }
    }
}